Micron Document
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| SparkN0de-git | SparkN0de |
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


Commit f2e7e098f9fc50d96a75183cb4c1a1557bcd1e77


Parents : ee6cc9f
Author : Mark Qvist <mark@unsigned.io>
Date : 2021-09-23T19:04:52+02:00

Added browser cache cleanup on startup.

Changes

1 files changed, 18 insertions(+), 0 deletions(-)


Diff

diff --git a/nomadnet/ui/textui/Browser.py b/nomadnet/ui/textui/Browser.py
index ba85a03..edc8ca2 100644
--- a/nomadnet/ui/textui/Browser.py
+++ b/nomadnet/ui/textui/Browser.py
@@ -90,6 +90,8 @@ class Browser:
if self.destination_hash != None:
self.load_page()
+ self.clean_cache()
+
def current_url(self):
if self.destination_hash == None:
return ""
@@ -697,6 +699,22 @@ class Browser:
return None
+ def clean_cache(self):
+ files = os.listdir(self.app.cachepath)
+ for file in files:
+ cachepath = self.app.cachepath+"/"+file
+ try:
+ components = file.split("_")
+ if len(components) == 2 and len(components[0]) == 64 and len(components[1]) > 0:
+ expires = float(components[1])
+
+ if time.time() > expires:
+ RNS.log("Removing stale cache entry "+str(file), RNS.LOG_DEBUG)
+ os.unlink(cachepath)
+
+ except Exception as e:
+ pass
+
def cache_page(self, cache_time):
url_hash = self.url_hash(self.current_url())


──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────